<template>
	<el-row>
		<el-row>
			<el-col :span="10">
				<el-form ref="form" :model="form" label-width="100px">
					<el-form-item label="管理员名称">
						<el-input v-model="form.name"></el-input>
					</el-form-item>
					<el-form-item label="电话">
						<el-input v-model="form.phone"></el-input>
					</el-form-item>
					<el-form-item label="头像">
						<el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
							:show-file-list="false" :on-success="handleAvatarSuccess"
							:before-upload="beforeAvatarUpload">
							<img v-if="imageUrl" :src="imageUrl" class="avatar">
							<i v-else class="el-icon-plus avatar-uploader-icon"></i>
						</el-upload>

					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="onSubmit">修改</el-button>
						<el-button>重置</el-button>
					</el-form-item>
				</el-form>
			</el-col>
		</el-row>
	</el-row>
</template>

<script>
	export default {
		data() {
			return {
				imageUrl: '',
				form: {},
				re_form: {}
			}
		},
		methods: {
			onSubmit() {
				console.log('submit!');
			},
			handleAvatarSuccess(res, file) {
				this.imageUrl = URL.createObjectURL(file.raw);
			},
			beforeAvatarUpload(file) {
				const isJPG = file.type === 'image/jpeg';
				const isLt2M = file.size / 1024 / 1024 < 2;

				if (!isJPG) {
					this.$message.error('上传头像图片只能是 JPG 格式!');
				}
				if (!isLt2M) {
					this.$message.error('上传头像图片大小不能超过 2MB!');
				}
				return isJPG && isLt2M;
			}
		}
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
</style>
